#ifndef __EEPROM_H
#define __EEPROM_H

#include "sys.h"

#define EE_INIT_FLAG	0x11

#define EE_DATA_INIT    0x00
#define EE_DATA_START   EE_DATA_INIT+1

#define EE_24C02  0x00
#define EEPROM_ADDRESS (0xa0 | EE_24C02)

#define EE_WRITE    (EEPROM_ADDRESS & 0xfe)
#define EE_READ     (EEPROM_ADDRESS | 0X01)

#define EE_SCL_PIN  GPIO_Pin_8
#define EE_SDA_PIN  GPIO_Pin_9
#define EE_PIN_PORT GPIOB
#define EE_PIN_CLK  RCC_AHB1Periph_GPIOB

#define EE_SCL_HIGH GPIO_SetBits(EE_PIN_PORT, EE_SCL_PIN)
#define EE_SCL_LOW  GPIO_ResetBits(EE_PIN_PORT, EE_SCL_PIN)

#define EE_SDA_HIGH GPIO_SetBits(EE_PIN_PORT, EE_SDA_PIN)
#define EE_SDA_LOW  GPIO_ResetBits(EE_PIN_PORT, EE_SDA_PIN)
#define EE_SDA_READ GPIO_ReadInputDataBit(EE_PIN_PORT, EE_SDA_PIN)

typedef struct
{
	float ampGateVoltage;	//栅极电压
	float fwdRFratio;		//映射系数
	uint16_t pMapValue;		//映射值
	uint16_t pProtect;		//保护阈值
} eeprom_data_t;

int EEPROM_Configuration(eeprom_data_t* eeprom_data);
void EEPROM_Write(uint16_t address, uint8_t data);
uint8_t EEPROM_Read(uint8_t address);
void EEPROM_ContinuousWrite(uint8_t addr, uint8_t* data, uint8_t lenth);
void EEPROM_ContinuousRead(uint8_t addr, uint8_t* data, uint8_t lenth);

#endif
